<template>
  <view class="login-bg">
    <view class="login-card">
      <view class="tab-bar">
        <view :class="['tab-item', activeTab === 0 ? 'active' : '']" @click="activeTab = 0">Account login</view>
        <view :class="['tab-item', activeTab === 1 ? 'active' : '']" @click="activeTab = 1">Facial recognition</view>
      </view>
      <view v-if="activeTab === 0">
        <view class="input-label">Email</view>
        <view class="input-wrapper">
          <image class="input-icon" src="/static/user-icon.png" />
          <input class="input" v-model="email" placeholder="Email" />
        </view>
        <view class="input-label">Password</view>
        <view :class="['input-wrapper', passwordError ? 'input-error' : '']">
          <image class="input-icon" src="/static/pwd-icon.png" />
          <input class="input" :type="showPwd ? 'text' : 'password'" v-model="password" placeholder="Password" />
          <image class="eye-icon" :src="showPwd ? '/static/eye-open.png' : '/static/eye-close.png'" @click="showPwd = !showPwd" />
        </view>
        <view v-if="passwordError" class="error-text">Wrong Password</view>
        <view class="form-row">
          <label class="checkbox-label">
            <checkbox v-model="rememberMe" color="#1ecb6c" />
            <text>Remember Me</text>
          </label>
          <text class="forgot-link" @click="onForgot">Forgot Password</text>
        </view>
        <button class="login-btn" @click="onLogin">Sign In</button>
        <view class="divider-row">
          <view class="divider"></view>
          <text class="divider-or">OR</text>
          <view class="divider"></view>
        </view>
        <button class="phone-btn" @click="onPhoneLogin">
          <image class="phone-icon" src="/static/phone-icon.png" />
          <text>Sign in With Phone</text>
        </button>
        <view class="bottom-row">
          <text>Don't have an account?</text>
          <text class="signup-link" @click="onSignUp">Sign Up Here</text>
        </view>
      </view>
      <view v-else class="face-login-placeholder">
        <text>Facial recognition 登录功能待实现</text>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      activeTab: 0,
      email: '',
      password: '',
      showPwd: false,
      rememberMe: false,
      passwordError: false
    }
  },
  methods: {
    onLogin() {
      if (!this.email || !this.password) {
        uni.showToast({ title: '请输入邮箱和密码', icon: 'none' })
        return
      }
      // 假设密码错误演示
      if (this.password !== '12345678') {
        this.passwordError = true
        return
      }
      this.passwordError = false
      uni.showToast({ title: '登录中...', icon: 'loading' })
    },
    onForgot() {
      uni.showToast({ title: '忘记密码功能待实现', icon: 'none' })
    },
    onPhoneLogin() {
      uni.showToast({ title: '手机号登录功能待实现', icon: 'none' })
    },
    onSignUp() {
      uni.showToast({ title: '注册功能待实现', icon: 'none' })
    }
  }
}
</script>

<style>
.login-bg {

}
.login-card {
  width: 100vw;
  min-height: 800rpx;
  background: #fff;
  border-radius: 48rpx 48rpx 0 0;
  box-shadow: 0 -8rpx 32rpx rgba(0,0,0,0.08);
  padding: 60rpx 40rpx 40rpx 40rpx;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tab-bar {
  display: flex;
  flex-direction: row;
  margin-bottom: 30rpx;
  border-bottom: 2rpx solid #e5e5e5;
  width: 100%;
}
.tab-item {
  flex: 1;
  text-align: center;
  font-size: 36rpx;
  color: #aab0bb;
  font-weight: 500;
  padding-bottom: 16rpx;
  position: relative;
}
.tab-item.active {
  color: #1a2233;
  font-weight: bold;
}
.tab-item.active::after {
  content: '';
  display: block;
  width: 60rpx;
  height: 4rpx;
  background: #1ecb6c;
  border-radius: 2rpx;
  margin: 0 auto;
  margin-top: 8rpx;
}
.input-label {
  font-size: 26rpx;
  color: #5a6273;
  margin: 24rpx 0 8rpx 8rpx;
  align-self: flex-start;
}
.input-wrapper {
  display: flex;
  align-items: center;
  border: 2rpx solid #bfc8d6;
  border-radius: 16rpx;
  padding: 0 20rpx;
  margin-bottom: 18rpx;
  background: #f8fafc;
  width: 100%;
  height: 90rpx;
}
.input-icon {
  width: 36rpx;
  height: 36rpx;
  margin-right: 12rpx;
}
.input {
  flex: 1;
  height: 90rpx;
  border: none;
  background: transparent;
  font-size: 30rpx;
  color: #1a2233;
}
.eye-icon {
  width: 36rpx;
  height: 36rpx;
  margin-left: 12rpx;
}
.input-error {
  border: 2rpx solid #ff4d4f !important;
  background: #fff6f6 !important;
}
.error-text {
  color: #ff4d4f;
  font-size: 24rpx;
  margin-bottom: 8rpx;
  margin-left: 8rpx;
  align-self: flex-start;
}
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 30rpx;
  width: 100%;
}
.checkbox-label {
  display: flex;
  align-items: center;
  font-size: 26rpx;
  color: #222;
}
.forgot-link {
  color: #5a6273;
  font-size: 26rpx;
  text-decoration: underline;
}
.login-btn {
  width: 100%;
  height: 90rpx;
  background: linear-gradient(90deg, #1ecb6c 0%, #1ea7cb 100%);
  color: #fff;
  font-size: 32rpx;
  border-radius: 45rpx;
  font-weight: bold;
  margin-top: 10rpx;
  margin-bottom: 20rpx;
}
.divider-row {
  display: flex;
  align-items: center;
  width: 100%;
  margin: 30rpx 0 20rpx 0;
}
.divider {
  flex: 1;
  height: 2rpx;
  background: #e5e5e5;
  border-radius: 1rpx;
}
.divider-or {
  margin: 0 24rpx;
  color: #aab0bb;
  font-size: 26rpx;
}
.phone-btn {
  width: 100%;
  height: 90rpx;
  background: #fff;
  color: #232b3b;
  font-size: 32rpx;
  border-radius: 45rpx;
  font-weight: bold;
  border: 2rpx solid #bfc8d6;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20rpx;
}
.phone-icon {
  width: 36rpx;
  height: 36rpx;
  margin-right: 16rpx;
}
.bottom-row {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 10rpx;
  font-size: 26rpx;
  color: #222;
}
.signup-link {
  color: #1ecb6c;
  margin-left: 10rpx;
}
.face-login-placeholder {
  text-align: center;
  color: #aab0bb;
  font-size: 30rpx;
  margin: 60rpx 0;
}
</style>
